package com.lanyam.travel.base.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanyam.travel.base.entity.Permission;
import com.lanyam.travel.base.entity.RolePermission;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author rosson
 * @since 2020-01-24
 */
@Repository
public interface RolePermissionMapper extends BaseMapper<RolePermission> {

	@Select("SELECT p.* FROM permission p LEFT JOIN role_permission rp ON rp.permission_id = p.id WHERE rp.role_id = #{roleId} ")
	List<Permission> selectPermissionsByRoleId(String roleId);

	@Select("SELECT p.* FROM permission p \r\n" + 
			"LEFT JOIN role_permission rp ON rp.permission_id = p.id \r\n" + 
			"LEFT JOIN USER u ON u.role_id = rp.role_id \r\n" + 
			"WHERE u.id = #{userId}")
	List<Permission> selectPermissionsByUserId(String userId);

}
